//
// Created by cljh on 2023/3/28.
//

#ifndef BIN_PACKING_POLYGON_H
#define BIN_PACKING_POLYGON_H


#include <vector>
#include "Point.h"
#include "qpainterpath.h"

class Polygon{
public:
    Polygon(){
        pointVector=std::vector<Point>();
        lenth=0;
        offset=Vector();
//        offsetX=0;
//        offsetY=0;
    }
    std::vector<Point> pointVector;
    int lenth;
    Vector offset;
//    double offsetX;
//    double offsetY;
    double getx(int index){
        return pointVector[index].x;
    }
    double gety(int index){
        return pointVector[index].y;
    }
    Point getPoint(int index){
        return pointVector[index];
    }
    bool isMarked(int index){
        return getPoint(index).mark;
    }
    void mark(int index){
        pointVector[index].mark= true;
    }
    void unmark(int index){
        pointVector[index].mark= false;
    }
    void add(Point point){
        pointVector.push_back(point);
        lenth++;
    }
    void add(double x,double y){
        Point point=Point(x,y);
        pointVector.push_back(point);
        lenth++;
    }
    bool isEmpty(){
        return pointVector.empty();
    }

    // 将 Polygon 转换为 QPolygonF todo:完全替换
    QPolygonF toQPolygonF() const {
        QPolygonF qPolygon;
        for (const auto& point : pointVector) {
            qPolygon.append(QPointF(point.x, point.y));
        }
        return qPolygon;
    }
};


#endif //BIN_PACKING_POLYGON_H
